﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Commonlib;
namespace DAL
{
    public class ClientDAL
    {
        /// <summary>
        /// 更新用户的身形图片信息
        /// </summary>
        public bool updatePosture(Albon.Model.Client client)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@userName",client.userName),
                new SqlParameter("@clientName",client.clientName),
                new SqlParameter("@postureidlist",client.postureIdList)
            };
            int ret=SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_clientupdate", parameters);
            return ret>0;
        }
        //添加客户
        public bool addClient(Albon.Model.Client client)
        {
            SqlParameter[] parameters = new SqlParameter[] {
                new SqlParameter("@userName",client.userName),
                new SqlParameter("@clientName",client.clientName),
                new SqlParameter("@sex",client.sex),
                new SqlParameter("@monoName",client.monoName)
            };
            int ret = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_clientadd", parameters);
            return ret>0;
        }

        //查询客户信息
        public DataTable getClient(string limit)
        {
            string cmdstr = "select * from Client where 1=1 and "+limit;
            return SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).Tables[0];
        }

        /// <summary>
        /// 添加客户身形数据信息
        /// </summary>
        /// <param name="posture"></param>
        /// <returns></returns>
        public bool addPosturePicture(Albon.Model.PosturePicture posture)
        {
            SqlParameter[] parameters =new SqlParameter[] {
					new SqlParameter("@ID", posture.ID),
					new SqlParameter("@postureName", posture.postureName),
					new SqlParameter("@imgPath", posture.imgPath),
					new SqlParameter("@parentID", posture.parentID),
					new SqlParameter("@remark", posture.remark)
            };
            int ret = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.StoredProcedure, "p_posturepictureadd", parameters);
            return ret > 0;
        }

        //删除客户身形数据
        public bool delPosturePicture(string id)
        {
            string cmdstr = "delete from PosturePicture where ID="+id;
            return  SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null)>0;
        }
        //获取客户身形数据
        public DataTable getPosturePicture(string limit)
        {
            string cmdstr = "select * from PosturePicture where 1=1 and "+limit;
            return SqlHelper.ExecuteDataSet(SqlHelper.SqlConnectionString, CommandType.Text, cmdstr, null).Tables[0];
        }
    }
}
